package com.ddzh.ratelimit;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * 实现根据 请求的 ip生成令牌
 */
@Component
public class IpKeyResolver implements KeyResolver {
    @Override
    public Mono<String> resolve(ServerWebExchange exchange) {
        Mono<String> key = Mono.just(exchange.getRequest().getRemoteAddress().getHostName());//返回令牌
        return key;
    }
}
